package com.sxbbc.bank.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sxbbc.bank.service.IBankLoanApplyRecordService;
import com.sxbbc.bank.service.IBankLoanApplyTrackService;
import com.sxbbc.common.core.entity.banks.BankLoanApplyTrack;
import com.sxbbc.common.core.mapper.banks.BankLoanApplyTrackMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2020-09-16
 */
@Service
public class BankLoanApplyTrackServiceImpl extends ServiceImpl<BankLoanApplyTrackMapper, BankLoanApplyTrack> implements IBankLoanApplyTrackService {


    @Autowired
    private IBankLoanApplyRecordService iBankLoanApplyRecordService;

    public List<BankLoanApplyTrack> listDate(String id){
        QueryWrapper<BankLoanApplyTrack> wrapper = new QueryWrapper<>();
        wrapper.eq("loan_apply_record_id",id);
        wrapper.orderByDesc("crate_time");
        return  super.list(wrapper);
    }


    public Boolean saveBankLoanApplyTrack(BankLoanApplyTrack bankLoanApplyTrack){
        LocalDateTime localDateTime=LocalDateTime.now();
        bankLoanApplyTrack.setCrateTime(localDateTime);
         if(super.save(bankLoanApplyTrack)){
             iBankLoanApplyRecordService.updateHandleResult(bankLoanApplyTrack.getLoanApplyRecordId(),1);
             return true;
         }
         return false;
    }


    public  BankLoanApplyTrack findByLoanApplyRecordId(String id){
        QueryWrapper<BankLoanApplyTrack> wrapper = new QueryWrapper<>();
        wrapper.eq("loan_apply_record_id",id);
        wrapper.orderByDesc("id");
        List<BankLoanApplyTrack> bankLoanApplyTracks=super.list(wrapper);
        if(bankLoanApplyTracks.size()>0){
            return  bankLoanApplyTracks.get(0);
        }
        return  null;
    }

}
